package com.nanhai.buddhist.college.module.collegebase.api.college;

import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import com.nanhai.buddhist.college.module.collegebase.api.college.dto.CollegesRespDTO;
import com.nanhai.buddhist.college.module.collegebase.convert.colleges.CollegesConvert;
import com.nanhai.buddhist.college.module.collegebase.dal.dataobject.colleges.CollegesDO;
import com.nanhai.buddhist.college.module.collegebase.service.colleges.CollegesService;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;

import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;
import static com.nanhai.buddhist.college.module.collegebase.enums.ApiConstants.VERSION;

@RestController // 提供 RESTful API 接口，给 Feign 调用
@DubboService(version = VERSION) // 提供 Dubbo RPC 接口，给 Dubbo Consumer 调用
@Validated
public class CollegeApiImpl implements CollegeApi {

    @Resource
    private CollegesService collegesService;

    @Override
    public CommonResult<List<CollegesRespDTO>> getCollegesList(Collection<String> ids) {
        List<CollegesDO> collegesList = collegesService.getCollegesList(ids);
        return success(CollegesConvert.INSTANCE.convertList03(collegesList));
    }

    @Override
    public CommonResult<CollegesRespDTO> getCollegesInfo(String id) {
        CollegesDO colleges = collegesService.getColleges(id);
        return success(CollegesConvert.INSTANCE.convertList04(colleges));
    }

    @Override
    public CommonResult<List<CollegesRespDTO>> getCollegesAll() {
        List<CollegesDO> collegesAllList = collegesService.getCollegesAllList();
        return CommonResult.success(CollegesConvert.INSTANCE.convertList06(collegesAllList));
    }
}
